package com.woniu.controller;

import com.woniu.been.entity.Courses;
import com.woniu.service.CoursesService;
import com.woniu.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/courses")
@CrossOrigin
public class CoursessController {
    @Autowired
    private CoursesService service;

    @GetMapping
    public Result<List<Courses>> list(@RequestParam Integer categoryId) {
        return Result.success(service.getCoursesByCategoryId(categoryId));
    }
    @PostMapping
    public Result<?> add(@RequestBody Courses course) {
        service.addCourse(course);
        return Result.success("新增成功");
    }
    @PutMapping("/{id}")
    public Result<?> update(@PathVariable Long id, @RequestBody Courses course) {
        course.setCourseId(id);
        service.updateCourse(course);
        return Result.success("修改成功");
    }
    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable Long id) {
        service.deleteCourse(id);
        return Result.success("删除成功");
    }
}